/*
 * @Author: xiaohao
 * @Date: 2025-10-30 07:06:33
 * @LastEditors: xiaohao
 * @LastEditTime: 2025-11-04 17:52:13
 * @FilePath: /Project/ConcurrentMemoryPool/test/unit/unit_ThreadCache.cpp
 * @Description:
 */
#include "ConcurrentMemoryPool/ConcurrentAlloc.h"
#include <iostream>
#include <thread>

void Alloc1()
{
    for (size_t i = 0; i < 5; ++i)
    {
        void *ptr = ConcurrentAlloc(6);
        std::cout << "Thread 1 allocated: " << ptr << std::endl;
        ConcurrentFree(ptr, 6);
    }
}

void Alloc2()
{
    for (size_t i = 0; i < 5; ++i)
    {
        void *ptr = ConcurrentAlloc(7);
        std::cout << "Thread 2 allocated: " << ptr << std::endl;
        ConcurrentFree(ptr, 7);
    }
}

int main()
{
    std::cout << "Testing ThreadCache with multiple threads..." << std::endl;

    std::thread t1(Alloc1);
    std::thread t2(Alloc2);

    t1.join();
    t2.join();

    std::cout << "ThreadCache test completed!" << std::endl;
    return 0;
}